package com.company.tanxin;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class CoveredIntervals {


    public static class Intervals {
        int left;
        int right;

        public Intervals(int left, int right) {
            this.left = left;
            this.right = right;
        }

        public boolean isCoveredBy(Intervals other) {
            return other.left <= left && other.right >= right;
        }
    }

    public int removeCoveredIntervals(int[][] intervals) {



        return doRemove(intervals);
    }


    private int doRemove(int[][] intervals) {
        List<Intervals> intervalsList = new ArrayList<>();
        for (int[] interval : intervals) {
            intervalsList.add(new Intervals(interval[0],interval[1]));
        }

        Set<Intervals> coveredList = new HashSet<>();
        for (Intervals current : intervalsList) {
            for (Intervals other : intervalsList) {
                if (other == current) {
                    continue;
                }
                if (current.isCoveredBy(other)) {
                    coveredList.add(current);
                }
            }
        }
        return intervalsList.size() - coveredList.size();
    }
}
